"""
应用相关数据模型
"""

from typing import Optional, List
from pydantic import BaseModel, Field, HttpUrl
from models.common import BaseEntity

class AppCategoryBase(BaseModel):
    """应用分类基础模型"""
    name: str = Field(..., max_length=100, description="分类名称")
    icon: Optional[str] = Field(None, description="分类图标")
    sort_order: int = Field(default=0, description="排序顺序")
    status: int = Field(default=1, description="状态(1:启用 0:禁用)")

class AppCategory(AppCategoryBase, BaseEntity):
    """应用分类模型"""
    pass

class ApplicationBase(BaseModel):
    """应用基础模型"""
    name: str = Field(..., max_length=100, description="应用名称")
    description: Optional[str] = Field(None, max_length=500, description="应用描述")
    icon: Optional[str] = Field(None, description="应用图标")
    url: Optional[HttpUrl] = Field(None, description="应用URL")
    category_id: int = Field(..., description="分类ID")
    sort_order: int = Field(default=0, description="排序顺序")
    is_internal: bool = Field(default=True, description="是否内部应用")
    status: int = Field(default=1, description="状态(1:启用 0:禁用)")

class Application(ApplicationBase, BaseEntity):
    """应用模型"""
    category: Optional[AppCategory] = None

class UserAppFavorite(BaseModel):
    """用户常用应用模型"""
    user_id: int = Field(..., description="用户ID")
    app_id: int = Field(..., description="应用ID")
    sort_order: int = Field(default=0, description="排序顺序")
    
    class Config:
        from_attributes = True

class QuickAction(BaseModel):
    """快速操作模型"""
    id: str = Field(..., description="操作ID")
    title: str = Field(..., description="操作标题")
    icon: str = Field(..., description="操作图标")
    route: str = Field(..., description="路由地址")
    color: str = Field(..., description="颜色")

class HomeData(BaseModel):
    """首页数据模型"""
    announcements: List[dict] = Field(default_factory=list, description="公告列表")
    quick_actions: List[QuickAction] = Field(default_factory=list, description="快速操作")
    statistics: dict = Field(default_factory=dict, description="统计数据")
    recent_activities: List[dict] = Field(default_factory=list, description="最近活动")
    banners: List[dict] = Field(default_factory=list, description="轮播图")
    news: List[dict] = Field(default_factory=list, description="企业新闻")